#!/usr/bin/env python

import sys
import re

def main():

   if len(sys.argv) == 3:

      cycle = 0

      f = open(sys.argv[1])

      for line in f:

         if line.startswith('DSC 0 0'):

            if re.search(sys.argv[2], line):

               cycle += 1

            line = line[0:7] + ' cycle#' + str(cycle) + ':' + line[8:]

         print line,

      f.close()


   else:
      sys.stderr.write("Usage: %s tdifile cyclepattern\n" % sys.argv[0])

if __name__ == "__main__":
   main()